package com.leased.controller;

import com.leased.enums.BusinessStatusEnum;
import com.leased.exception.YCException;
import com.leased.handler.CarsLocationHandler;
import com.leased.request.cuser.CUserListRequest;
import com.leased.response.CarsLocationResponse;
import com.leased.utils.APIResponse;
import com.leased.utils.YCSystemStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by shencx on 2017/8/4.
 */
@Controller
@RequestMapping(value = "/api/location")
public class CarsLocationController {

    final Logger LOG = LoggerFactory.getLogger(CarsLocationController.class);

    @Resource
    private CarsLocationHandler carsLocationHandler;

    /**
     * 获取车辆位置列表
     * @param request
     * @param cUserListRequest
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public APIResponse<List<CarsLocationResponse>> list(HttpServletRequest request, CUserListRequest cUserListRequest){
        APIResponse<List<CarsLocationResponse>> apiResponse = new APIResponse<>();
        List<CarsLocationResponse> list = null;
        try {
            list = carsLocationHandler.getCarsLocationList(cUserListRequest);
            apiResponse.setStatus(BusinessStatusEnum.SUCCESS.getCode());
            apiResponse.setMsg(BusinessStatusEnum.SUCCESS.getDesc());
            apiResponse.setData(list);
        } catch (Throwable e) {
            LOG.error("获取车辆位置列表发生异常", cUserListRequest);
            apiResponse.setStatus(YCSystemStatusEnum.SYSTEM_ERROR.getCode());
            apiResponse.setMsg(YCSystemStatusEnum.SYSTEM_ERROR.getDesc());
        }
        return apiResponse;

    }
}
